package com.maixy.rabbitmqdemo.normal;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @ClassName Receiver
 * @Description 消费者
 * @Date 2021/3/23 20:36
 * @Author maixy
 */
@Component
public class Receiver {

    //直连模式生产者
    @RabbitListener(queues = "hello1")
    @RabbitHandler
    public void receiver1(String str){
        System.out.println("Receiver1 says:[" + str + "]");
    }

    //work queues模式消费者1
    @RabbitListener(queues = "hello2")
    @RabbitHandler
    public void process1(String str) {
        try {
            Thread.sleep(200);
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("Receiver1 says:[" + str + "]-------------");
    }

    //work queues模式消费者2
    @RabbitListener(queues = "hello2")
    @RabbitHandler
    public void process2(String str) {
        System.out.println("Receiver2 says:[" + str + "]");
    }

    //fanout模式（广播模式）
    //消费队列fanout.A上的消息
    @RabbitListener(queues = "fanout.A")
    @RabbitHandler
    public void AMessage(String msg){
        System.out.println("Receiver form fanout.A:"+msg);
    }
    //消费队列fanout.B上的消息
    @RabbitListener(queues = "fanout.B")
    @RabbitHandler
    public void BMessage(String msg){
        System.out.println("Receiver form fanout.B:"+msg);
    }
    //消费队列fanout.C上的消息
    @RabbitListener(queues = "fanout.C")
    @RabbitHandler
    public void CMessage(String msg){
        System.out.println("Receiver form fanout.C:"+msg);
    }

    /***********************************Topic*****************************************/
    @RabbitListener(queues = "topic.message")
    @RabbitHandler
    public void topicMessage(String msg){
        System.out.println("Receiver topic.message:"+msg);
    }

    @RabbitListener(queues = "topic.messages")
    @RabbitHandler
    public void topicMessages(String msg){
        System.out.println("Receiver topic.messages:"+msg);
    }
}
